package org.example;

import lombok.RequiredArgsConstructor;
import org.example.dto.CourseDto;
import org.example.dto.CourseRequestDto;
import org.example.dto.PageDto;
import org.example.dto.ResultDto;
import org.example.service.CourseService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class CourseController {            //提供者模块
    private final CourseService courseService;

  //接收路径参数
    @GetMapping("/courses/{account}/{page}/{rows}")
    public ResultDto<PageDto<CourseDto>> queryCourse(@PathVariable("account") String account,
                                                     @PathVariable("page") Integer page,
                                                     @PathVariable("rows") Integer rows){
        return courseService.loadCourseByPage(account, page, rows);
    }

 //接收JSON参数

    @PostMapping("/courses")
    public ResultDto<PageDto<CourseDto>> loadCourseByJson(@RequestBody CourseRequestDto course){
        return courseService.loadCourseByPage(course.getAccount(), course.getPage(), course.getRows());
    }


  //接收Form参数
    @PostMapping("/courses1")
    public ResultDto<PageDto<CourseDto>> courseForm(CourseRequestDto course){
        return courseService.loadCourseByPage(course.getAccount(), course.getPage(), course.getRows());
    }

}
